import storage from 'store'
import { APP_USER } from '@/store/mutation-types'
import FilePreview from '@/views/materials/FilePreview.vue'
import FileComparison from '@/views/materials/FileComparison.vue'
import MaterialAppends from '@/views/materials/MaterialAppends.vue'
import TaskFormView from '@/views/workflow/Wf_TaskForm.vue'
import { Splitpanes, Pane } from 'splitpanes'
import 'splitpanes/dist/splitpanes.css'
import MoveModal from '@/components/Power/MoveModal.vue'
// import { getAttachAppendList, getMaterialAppends } from '@/api/apply/apl_attach_append'
 
export const reviewMixin = {
  props: {
    applyid: {
      // 申请id
      type: String,
      required: true
    },
    isEdit: {
      // 是否可编辑
      type: Boolean,
      required: true
    },
    selectData: {
      // 选中的材料数据
      type: Object,
      default: () => {
        return null
      }
    }
  },
  data() {
    return {
      currentUser: storage.get(APP_USER), //登陆人信息
      materialList: [],
      materialForm: {
        id: null, // 材料id
        name: null, // 材料名称
        status: null, // 材料状态
        opinion: null // 审查意见
      },
      rules: {
        status: [{ required: true, message: '请选择审查结论', trigger: 'change' }],
        opinion: [{ required: true, message: '请输入审查意见', trigger: 'blur' }]
      },
      chekcedFileId: null,
      materialIndex: 0, // 材料列表下标
      iWebPDFShow: false, // iWebPDF插件是否显示或正常启动
      loading: false, // 表格数据加载中
      isResize: false,
      tabKey: 1,
      visible: false, // 历史补正意见弹窗
      appendOpinionList: [] // 历史补正意见列表
    }
  },
  components: {
    FilePreview,
    FileComparison,
    MaterialAppends,
    TaskFormView,
    Splitpanes,
    Pane,
    MoveModal
  },
  methods: {
    // changeStatus() {
    //   this.$refs.ruleForm.clearValidate()
    //   if (this.materialForm.status == St_attachValue.APPEND) {
    //     this.rules = {
    //       status: [{ required: true, message: '请选择审查结论', trigger: 'change' }],
    //       opinion: [{ required: true, message: '请输入审查意见', trigger: 'blur' }]
    //     }
    //   } else {
    //     this.rules = {
    //       status: [{ required: true, message: '请选择审查结论', trigger: 'change' }]
    //     }
    //   }
    // },
    copyAnnotate() {
      let texts = this.$refs.FilePreview.bringBackAnnotate()
      if (texts.length) {
        let opinion = this.materialForm.opinion
        if (!opinion) {
          opinion = ''
        }
        let opinions = opinion.split('\n')
        // 找到最后一条的首位数
        let firstStr = opinions[opinions.length - 1].substring(0, opinions[opinions.length - 1].indexOf('.'))
        let index = 0
        if (!isNaN(firstStr)) {
          index = Number(firstStr)
        }
        texts.forEach((v, i) => {
          if (opinion) {
            opinion += '\n'
          }
          opinion = opinion + (index + i + 1) + '. ' + v
        })
        this.materialForm.opinion = opinion
      }
    },
    onClose() {
      this.$refs.FilePreview.clearPollingSave()
      this.$refs.FilePreview.saveFileAnnotate()
      this.$emit('onClose')
    },
    fpChange(iWebPDFShow) {
      this.iWebPDFShow = iWebPDFShow
    },
    checkedFile() {
      this.$nextTick(() => {
        // document.getElementById(this.chekcedFileId).scrollIntoView({
        //   behavior: 'smooth',
        //   block: 'center'
        // })
      })
    },
    resize() {
      this.isResize = true
    },
    resized() {
      this.isResize = false
    },
    tabChange() {
      if (this.tabKey == 1) {
        this.checkedFile()
      }
    },
    async openAppendOpinion() {
      this.visible = true
      this.appendOpinionList = []
      let res = await getAttachAppendList({ applyid: this.applyid })
      if (res.data && res.data.length) {
        this.appendOpinionList = res.data
      }
    },
    openMaterialAppends(material_name, material_entity, material_id) {
      this.$refs.MaterialAppends.open(material_name, material_entity, material_id)
    }
  }
}